﻿#ifndef UDPMULTICASTRECEIVER_H
#define UDPMULTICASTRECEIVER_H

#include <QObject>
#include <QUdpSocket>
#include <QNetworkDatagram>
#include <QDateTime>
#include <QFile>
#include <QDir>
#include <QMutex>

class UdpMulticastReceiver : public QObject
{
    Q_OBJECT

public:
    explicit UdpMulticastReceiver(QObject *parent = nullptr);

public:
    qint64 wenjian_changdu=0;


public slots:
    void start(const QString &multicastGroup,quint16 port);
    void stop();
    void start_wt();
    void stop_wt();

private slots:
    void readPendingDatagrams(QUdpSocket *socket);

private:
    QUdpSocket *udpSocket1;

    QFile *filePls;

    qint64 fileSizeLimit = 5368709120; // 5G
    QString dataPath;
    QString fileNamePls;

    bool isRunning;
    QMutex mutex;


    void initializeSocket(QUdpSocket *socket, quint16 port, const QString &multicastGroup);
    void processReceivedData(const QByteArray &data);
    void createNewFile();
    void checkAndCreateDataDir();


signals:
    void newDataReceived(const QByteArray &data, const QString &fileName);
};

#endif // UDPMULTICASTRECEIVER_H
